$(function () {
  function getuserdata() {
    $.ajax({
      url: '/my/userinfo',
      type: 'get',
      data: {},
      success: function (res) {
        // 显示图片
        if (res.data.user_pic) {
          if (res.status == 0) {
            $('.userinfo img').attr('src', res.data.user_pic)
            $('.text-avatar').hide()
          } else {
            $('.userinfo img').hide()
            $('.text-avatar').show().html(res.data.username[0].toUpperCase())
          }
        }
        // console.log(res.data.nickname, 5555)
        $('#welcome').html('欢迎  &nbsp &nbsp' + res.data.nickname)
        //存储数据
        localStorage.setItem('uesrdata', JSON.stringify(res.data))
        // window.parent.$('#welcome').html(res.data.nickname)
        window.getuserdata = getuserdata
      }
    })
  }
  // window.getuserdata = getuserdata
  getuserdata()

  //点击退出
  $('#tuichu').on('click', function () {
    localStorage.removeItem('token')
    location.href = '/login.html'
  })
})
